<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var p = new Promise(function(resolve,reject){
            //这里用于实现异步任务
            setTimeout(() => {
                var flag = true
                if(flag){
                    resolve('hello')
                }else{
                    reject('出错了')
                }
            }, 1500);
        })
        p.then(function(res){
            console.log(res)
        },function(err){
            console.log(err)
        })

        //实际上就是把之前用到的回调函数，用then的方式重构了.代码不再是层层嵌套了，变成了线性结构
    </script>
</body>
</html>